//验证手机号
function isPoneAvailable($poneInput) {  
          var myreg=/^[1][3,4,5,7,8][0-9]{9}$/;  
          if (!myreg.test($poneInput.val())) {  
              return false;  
          } else {  
              return true;  
          }  
      };
//验证邮编  
/*function is_postcode(postcode) {  
    	 if ( postcode == "") {  
    	        return false;  
    	    } else {  
    	        if (! /^[0-9][0-9]{5}$/.test(postcode)) {  
    	            return false;  
            }  
    	   }  
     return true;  
};*/
$('.phone').blur(function(){
	if(!isPoneAvailable($('.phone'))){
		this.value='';
		$('.message').html('请填写正确的手机号');
	}else{
		 $('.message').html('');
		return true;
	}
})   	  

//验证所有的信息填写完毕,不为空
function myCheck()
      {
        for(var i=0;i<$('input').length-1;i++)
        {
         if( $('input')[i].value=="")
         {
          $('.message').html("请完善当前所有信息,不能有空项");
          $('input')[i].focus();
           return false;
         }
        }
        $('.message').html('');
        return true;
        
};
//
var isSubmit = false;
$('.btn').click(function(){
	if(!myCheck()){
		return false;
	}
	if (isSubmit) {
		return;
	}
	$(".btn").attr({
		"disabled" : "disabled"
	});
	var _phone = $("input[name=phone]").val();
	var _alipayid = $("input[name=alipayid]").val();
	var _wechatid = $("input[name=wechatid]").val();
	var _postbankid = $("input[name=postbankid]").val();
	 // 
	  var a = new FormData();
      a.append("file", $("#fileId")[0].files[0]);
      a.append("phone",_phone );
      a.append("alipayid",_alipayid);
      a.append("wechatid",_wechatid );
      a.append("postbankid",_postbankid );
      console.log(_phone);
      console.log($("#fileId")[0].files[0]);
      console.log(a.get("file"))
      console.log(a.get("phone"));
	isSubmit = true;
	$.ajax({
		  type : "POST",
		  url:"/service/user/doShopRegister",
          xhrFields:{
                  withCredentials:true
          },
          type: "POST",
          cache: false,
          data: a,
          processData: false,
          contentType:false,
          async: false,
		  success : function(result) {
			if(result.status == "200"){
				// 注册成功，去卖家中心
				$('.message').html('卖家注册成功');
				$(".btn").removeAttr("disabled");
				isSubmit = false;
				return;
			}else{
				$('.message').html('卖家注册失败');
			}
	    }
})
//		$.ajax({
//type : "POST",
//url : "/service/user/doShopRegister",
//contentType : "application/x-www-form-urlencoded; charset=utf-8",
//data : {phone:_phone,alipayid:_alipayid,wechatid:_wechatid,postbankid:_postbankid,images:_images},
//dataType : 'json',
//success : function(result) {
//	if(result.status == "200"){
//
//		$('input').val('');
//		showMessage('已发送申请，申请通过后将以< a href=" " >短信</ a>的形式通知信！');
//	
//		verc();
//		$("#registsubmit").removeAttr("disabled").removeClass()
//				.addClass("btn-img btn-regist");
//		isSubmit = false;
//		return;
//	}else{
//		$('#mobileCode_error').show().removeClass().addClass('error').html('申请失败');
//		$("#registsubmit").removeAttr("disabled").removeClass()
//		.addClass("btn-img btn-regist");
//		isSubmit = false;
//		return;
//	}
//}
//});
});
var isDel=false;
//删除收货地址
$('.del').click(function(){
	if (isDel) {
		return;
	}
	$(".del").attr({
		"disabled" : "disabled"
	});
	var _id = $(".del").attr("data-id");
	console.log(_id)
	isDel = true;
	$.ajax({
		type : "POST",
		url : "/service/receiver/delete?id="+_id,
		contentType : "application/x-www-form-urlencoded; charset=utf-8",
		data : {},
		dataType : 'json',
		success : function(result) {
			if(result.status == "200"){
				alert('删除成功');
				window.location.reload(); 
				isDel = false;
				return;
			}else{
				alert('删除失败');
			}
	    }
})

});
















